from abc import abstractmethod

# class Person:
#     def eat(self):
#         print("吃饭")
#
#     def call(self,name):
#         print(f"打电话给{name}")
#
# # 相当于创建一个Person类的对象，将对象的地址值赋值给变量p1
# p1 = Person() # 在内存中开辟一个新的空间
# p1.eat()
# p1.call('马云')
# print("----------------------------")
# p2 = Person() # 在内存中开辟一个新的空间
# p2.eat()
# p2.call('马云')
# print(id(p1)==id(p2)) # False

from typing import overload

from typing_extensions import override


# class Person:
#     def eat(self):
#         print("吃饭")
#
#     def call(self,name):
#         print(f"打电话给{name}")
#
# p1 = Person()
# p1.name = '小虎'
# print(f"p1对象的姓名为：{p1.name}")
#
# p2 = Person() # 在内存中开辟一个新的空间
# p2.name = '张三'
# print(f"p2对象的姓名为：{p2.name}") # 报错


# class Person:
#     def __init__(self,name):
#         # self.name 定义一个类中的属性,叫做name
#         self.name = name
#
#     def eat(self):
#         print("吃饭")
#
#     def call(self,name):
#         print(f"打电话给{name}")
#
# # 使用类名() 的方式创建对象,实际上底层调用的是类中的__init__(self)
# # 若自己没写,默认一个类中有一个__init__(self),且只能有一个
# p1 = Person('小虎')
# print(f"p1对象的姓名为：{p1.name}")
#
# p2 = Person('张三')
# print(f"p2对象的姓名为：{p2.name}")


# # 手机
# '''
# 手机:
#     属性: 品牌, 价格, 颜色
#     行为:打电话, 发短信
# '''
#
#
# class Phone:
#     def __init__(self, brand, price, color):
#         self.brand = brand
#         self.price = price
#         self.color = color
#
#     def call(self):
#         print("打电话")
#
#     def send_message(self):
#         print("发短信")
#
#
# # 创建第一部手机
# p1 = Phone('小米15 pro', 5799, '黑色')
# print(f"手机的品牌为:{p1.brand}, 价格:{p1.price}, 颜色:{p1.color}")
# p1.call()
# p1.send_message()

# def fun1(a1,b1,c1,d1):
#     pass
#
# def fun2(a1,b1,c1,d1):
#     pass
#
# def fun3(a1,b1,c1,d1):
#     pass
#
# fun1(11,22,33,44)
# fun2(11,22,33,44)
# fun3(11,22,33,44)

# class Demo:
#     # 构造函数
#     def __init__(self,a1,b1,c1,d1):
#         self.a1 = a1
#         self.b1 = b1
#         self.c1 = c1
#         self.d1 = d1
#
#     def fun1(self):
#         print(f"a1:{self.a1},b1:{self.b1},c1:{self.c1},d1:{self.d1}")
#
#     def fun2(self):
#         print(f"a1:{self.a1},b1:{self.b1},c1:{self.c1},d1:{self.d1}")
#
#     def fun3(self):
#         print(f"a1:{self.a1},b1:{self.b1},c1:{self.c1},d1:{self.d1}")
#
# d1 = Demo(11,22,33,44)
# d1.fun1()
# d1.fun2()
# d1.fun3()

#
# '''
# list1 = [
#     p1,
#     p2,
#     p3,
#     ...
# ]
# '''
#
# class Person:
#     def __init__(self,n1,a1):
#         self.name = n1
#         self.age = a1
#
#     def eat(self):
#         print("吃饭")
#
#     def sleep(self):
#         print("睡觉")
#
#     # 该函数将来在直接使用对象名的时候,自动被掉调用
#     # __str__()函数必须要有一个返回值
#     def __str__(self):
#         return f"姓名:{self.name}, 年龄:{self.age}"
#
#     # def show(self):
#     #     print(f"姓名:{self.name}, 年龄:{self.age}")
#
#
# user_list = []
# while True:
#     name = input("请输入用户的姓名:")
#     if name.upper()=='Q':
#         break
#     age = input("请输入用户的年龄:")
#     # 创建一个学生对象
#     p = Person(name,age)
#
#     user_list.append(p)

# for i in user_list:
#     print(i)  # 若直接使用对象名, 默认调用的是一个class类中的__str__()函数


#
# for per in user_list:
#     print(f"姓名:{per.name}, 年龄:{per.age}")

# class Student:
#     def __init__(self,name,age):
#         self.__name = name
#         self.__age = age
#
#     def __str__(self):
#         return f"姓名:{self.__name}, 年龄:{self.__age}"
#
#     def set_name(self,name):
#         self.__name = name
#
#     def get_name(self):
#         return self.__name
#
#     def set_age(self,age):
#         if 120>=age>0:
#             self.__age = age
#         else:
#             print("您给的年龄不合法,默认已修改为18!")
#             self.__age = 18
#
#     def get_age(self):
#         return self.__age
#
#     def eat(self):
#         print("吃饭")
#
#     def sleep(self):
#         print("睡觉")
#
#     def __fun1(self):
#         print("hello world")
#
#     def fun2(self):
#         self.__fun1()
#
#
# s1 = Student("张成阳", 11)
# print(s1)
# print("-----------------------------------")
# # s1.age = 1900 # 这里的age相当于是一个新的属性
# # s1.__age = 1900 # 使用不了__的属性
# # s1.set_age(29)
# # print(s1)
#
# # print(s1.__age)
#
# # print(s1.get_age())
# # s1.fun1()
# s1.fun2() # 间接地调用私有的函数


# class Demo1:
#     def __init__(self, age):
#         self.age = age
#
#     def fun1(self):
#         # age = 10
#         print(self.age)  # 获取当前对象的属性age
#         # print(age) # 获取当前函数中的局部变量age
#
#
#
# d1 = Demo1(18)
# d1.fun1()

# class Person:
#     def __init__(self,sid,name,age):
#         self.sid = sid
#         self.name = name
#         self.age = age
#
#     def __str__(self):
#         return f"Student:({self.sid}, {self.name}, {self.age})"
#
#     def study(self):
#         print("学生学习")
#
#     def like(self):
#         print("学生的爱好")
#
# class Student(Person):
#     pass
#
# class HighStudent(Person):
#     pass
#
#
# s1 = Student('1001','张三',18)
# s1.study()
# s1.like()
# s2 = HighStudent('1002','李四',19)
# s2.study()
# s2.like()

# class Fu:
#     def fun1(self):
#         print("好好学习，天天向上！")
#
#     def __fun2(self):
#         print("这是父类中私有的成员函数__fun2")
#
#     def fun3(self):
#         self.__fun2()
#
# class Son(Fu):
#     @override
#     def fun1(self):
#         print("这是子类中的函数fun1")
#
#     pass
#
# s1 = Son()
# s1.fun1()
# # s1.__fun2()
# # s1.fun3()
# class Fu2:
#     def fun1(self):
#         print("shujia")
#
#
# class Zi2(Fu2):
#     def show(self):
#         print("shujia666")
#
#
# # d1 = Fu2()
# # d1.fun1()
# # d1.show()
# d2 = Zi2()
# d2.fun1()
# d2.show()

# class Fu:
#     def fun1(self):
#         print("这是父类中的fun1")
#
#
# class Zi(Fu):
#     def fun1(self):
#         print("这是子类中的fun1")
#
#     def show(self):
#         self.fun1()  # 调用的是子类中重写后的fun1函数
#         # 调用父类中的fun1
#         super().fun1()
#
# z = Zi()
# z.show()

# class Fu:
#     def __init__(self,name,age):
#         self.name = name
#         self.age = age
#
# class Zi(Fu):
#     def __init__(self, name, age, sid):
#         super().__init__(name,age)
#         self.sid = sid
#
# z1 = Zi('张三',18, 1001)
# print(z1.name,z1.age,z1.sid)

# class Fu:
#     def fun1(self):
#         print("这是父亲中的函数fun1")
#
#     def show(self):
#         print("这是父亲中的函数show")
#
#
# class Mather:
#     def fun2(self):
#         print("这是母亲中的函数fun2")
#
#     def show(self):
#         print("这是母亲中的函数show")
#
#
# class Son(Mather,Fu):
#     def function1(self):
#         print("这是儿子自己的函数")
#
#
# s1 = Son()
# s1.fun1()
# s1.fun2()
# s1.function1()
# s1.show()

# class Animal:
#     def __init__(self, name, age):
#         self.name = name
#         self.age = age
#
#     def __str__(self):
#         return f"name:{self.name}, age:{self.age}"
#
#     @abstractmethod
#     def eat(self):
#         pass
#
#     @abstractmethod
#     def sleep(self):
#         pass
#
#
# class Dog(Animal):
#     @override
#     def eat(self):
#         print("🐕吃🥩")
#
#     @override
#     def sleep(self):
#         print("🐕趴着睡")
#
# # a1 = Animal('小黄',2)
# a1 = Dog('小黑',3)
# a1.eat()
# a1.sleep()
# print(a1)
#
# # Animal a = new Dog('小黑',3)

class Demo1:
    # 类变量
    a = 100

    def fun1(self):
        a = 10
        print(a)
        print(Demo1.a)


d1 = Demo1()
d1.fun1()
# print(Demo1.a) # 通过类名直接访问
print(d1.a) # 也可以通过对象名进行访问